package com.yiip.gmall.manager.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.yiip.gmall.beans.*;
import com.yiip.gmall.service.CatalogService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@CrossOrigin
public class CatelogController {

    @Reference
    CatalogService catalogService;

    /**
     * 获取一级分类
     * @return
     */
    @RequestMapping("/getCatalog1")
    @ResponseBody
    public List<PmsBaseCatalog1> getCatalog1() {
        List<PmsBaseCatalog1> catalog1s = catalogService.getCatalog1();
        return catalog1s;
    }

    /**
     * 获取二级分类
     * @return
     */
    @RequestMapping("/getCatalog2")
    @ResponseBody
    public List<PmsBaseCatalog2> getCatalog2(String catalog1Id) {
        List<PmsBaseCatalog2> catalog2s = catalogService.getCatalog2(catalog1Id);
        return catalog2s;
    }

    /**
     * 获取三级分类
     * @return
     */
    @RequestMapping("/getCatalog3")
    @ResponseBody
    public List<PmsBaseCatalog3> getCatalog3(String catalog2Id) {
        List<PmsBaseCatalog3> catalog3s = catalogService.getCatalog3(catalog2Id);
        return catalog3s;
    }

    /**
     * 根据三级分类，获取属性列表
     * @return
     */
    @RequestMapping("/attrInfoList")
    @ResponseBody
    public List<PmsBaseAttrInfo> attrInfoList(String catalog3Id) {
        List<PmsBaseAttrInfo> pmsBaseAttrInfos = catalogService.getBaseAttrInfoList(catalog3Id);
        return pmsBaseAttrInfos;
    }

    /**
     * 保存平台属性
     * @param pmsBaseAttrInfo
     */
    @RequestMapping("/saveAttrInfo")
    @ResponseBody
    public void saveAttrInfo(@RequestBody PmsBaseAttrInfo pmsBaseAttrInfo) {
        catalogService.saveAttrInfo(pmsBaseAttrInfo);
    }

    /**
     * 获取销售属性
     * @param attrId
     * @return
     */
    @RequestMapping("/getAttrValueList")
    @ResponseBody
    public List<PmsBaseAttrValue> getAttrValueList(String attrId) {
        List<PmsBaseAttrValue> pmsBaseAttrValueList = catalogService.getAttrValueList(attrId);
        return pmsBaseAttrValueList;
    }


}
